﻿<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="SelectSubMedia.aspx.vb" Inherits="Slxt.SelectSubMedia" %>
<%@ Register TagPrefix="pomcnt" Namespace="Mysoft.PubProject.Business" Assembly="Mysoft.PubProject.Business" %>
<%@ Register TagPrefix="mnu" Namespace="Mysoft.Map.Application.Menus" Assembly="Mysoft.Map.Application.Components" %>
<%@ Register TagPrefix="cnt" Namespace="Mysoft.Map.Application.Controls" Assembly="Mysoft.Map.Application.Components" %>
<%@ Register TagPrefix="mwc" Namespace="MySoft.WebControls" Assembly="MySoft.WebControls" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head id="Head1" runat="server">
    <title>选择媒体子类</title>
    <script type="text/javascript" src="/_controls/settings.aspx"></script>
	<link rel="stylesheet" type="text/css" href="/_common/styles/global.css" />
	<link rel="stylesheet" type="text/css" href="/_common/styles/dialogs.css" />
	<link rel="stylesheet" type="text/css" href="/_nav/taskbox.css" />
	<link rel="stylesheet" type="text/css" href="/_controls/tree/tree.css" />
	<link href="/_nav/tabs.css" type="text/css" rel="stylesheet" />
	<script type="text/javascript" src="/_common/scripts/global.js"></script>
	<script type="text/javascript" src="/_controls/util/util.js"></script>
	<script type="text/javascript" src="/_forms/FormBase.js"></script>
	<script language="javascript" type="text/javascript" src="/_controls/lookup/map_lookup.js"></script>
    <script language="javascript" type="text/javascript" src="/_controls/lookup/map_LookupDialogs.js"></script>
		<script language="javascript" type="text/javascript">
		    window.onload = function() {
		        // 默认展开2级(根级除外)
		        tblSubMedia.showLevel(3);
		    }

//		    function initTree() {
//		        var i, j;
//		        var aryName = dialogArguments.parentElement.previousSibling.firstChild.value.split(";");
//		        var strTempName;
//		        for (i = 0; i < tblSubMedia.rows.length; i++) {
//		            strTempName = tblSubMedia.rows[i].cells[0].children[2].children[0].text;
//		            for (j = 0; j < aryName.length; j++) {
//		                if (strTempName == aryName[j]) {
//		                    tblSubMedia.rows[i].cells[0].children[2].children[0].checked = true;
//		                    selectParentCheck(tblSubMedia.rows[i].cells[0].children[2].children[0].value);
//		                    break;
//		                }
//		            }
//		        }
//		    }
        
            // 选中节点
		    function selectNode(o) {
		        SelectCharindex(o.parentElement.parentElement.parentElement.code, o.checked);
		    }
    		
		    // 选中子节点
		    function SelectCharindex(strSelectCode, blnCheck) {
		        var strCode;
		        var i, j;
		        for (i = 0; i < tblSubMedia.rows.length; i++) {
		            strCode = tblSubMedia.rows[i].code + ".";
		            j = strCode.indexOf(strSelectCode + ".");
		            if (j >= 0) {
		                tblSubMedia.rows[i].cells[0].children[2].children[0].checked = blnCheck;
		            }
		        }

		        selectParentCheck(strSelectCode);
		    }
            
            // 反向选中父节点
		    function selectParentCheck(strChildCode) {
		        var strParentCode, strCode;
		        // 子节点存在父级时
		        if (strChildCode.lastIndexOf(".") >= 0) {
		            // 表示子节点的所有兄弟节点是否全部选中
		            var blnFlg = false;     
		            var i, j;
		            var intRowCount = tblSubMedia.rows.length;
		            // 获取父节点CODE
		            strParentCode = strChildCode.substring(0, strChildCode.lastIndexOf("."));
		            for (i = 0; i < intRowCount; i++) {
		                strCode = tblSubMedia.rows[i].code;
		                // 当前节点CODE为父级节点CODE 且 当前节点未选中，则表示该父节点的子节点未全部选中，即该父节点不选中
		                // 否则该父节点选中
		                if (strCode.substring(0, strCode.lastIndexOf(".")) == strParentCode) {
		                    if (!tblSubMedia.rows[i].cells[0].children[2].children[0].checked) {
		                        blnFlg = false;
		                        break;
		                    } else {
		                        blnFlg = true;
		                    }
		                }
		            }
		            // 遍历所有节点的CHECKBOX，选中上一步子节点和其兄弟节点全部选中的父节点
		            // 没有父节点是跳数
		            var chkBlds = document.all("chkBld");
		            var intBldLength = chkBlds.length;
		            for (j = 0; j < intBldLength; j++) {
	                    if (chkBlds[j].value == strParentCode) {
	                        chkBlds[j].checked = blnFlg;
	                        if (selectParentCheck(strParentCode))
	                            return true;
	                    }
	                } 
		        }
		        return false;
		    }
    		
		    // 返回选中的媒体子类名称
		    function selectItem(){
		        var obj = document.all("chkBld");
		        var strCodeList = ""
		        var strNameList = "";
		        for (i = 0; i < obj.length; i++) {
		            if (obj[i].checked && obj[i].allowselect == "1") {
		                strCodeList += ";" + obj[i].value;
		                strNameList += ";" + obj[i].text;
		            }
		        }
                
		         var ls = new LookupItems();
                 var li = new LookupItem();
                 li.id = strCodeList.substr(1);
                 li.name = strNameList.substr(1);
                 li.html = null;
                 li.values = null;
                 li.keyValues = null;
                 ls.items.push(li);

                 window.returnValue = ls;
	             window.close();
		    }
		</script>
	</HEAD>
	<body MS_POSITIONING="GridLayout">
	<form id="mapForm" runat="server">
			<table width="100%" cellspacing="0" cellpadding="0" height="100%">
				<tr>
					<td class="main" colspan="2">
						<table width="100%" cellspacing="0" cellpadding="0" height="100%">
							<TBODY>
								<tr height="26">
									<td>    
									    &nbsp;
									</td>
								</tr>
								<tr>
									<td class="wizBox1">
                                            <div style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px; overflow: auto;
                                                width: 100%; padding-top: 5px; height: 100%">
                                                <mwc:Repeater ID="repSubMedia" runat="server" SortSignDESC='<img src="/_imgs/ico_arrow_d.gif">'
                                                    SortSignASC='<img src="/_imgs/ico_arrow_u.gif">' PKField="BldCode" LinkAlign="right"
                                                    LinkCssClass="a1" FooterCssClass="footer" EnablePager="false">
                                                    <HeaderTemplate>
                                                        <table id="tblSubMedia" cellspacing="0" cellpadding="0" width="100%" class="singleSelectTree" ismultiselect="1">
                                                    </HeaderTemplate>
                                                    <ItemTemplate>
                                                        <tr height='20'
                                                            code='<%# DataBinder.Eval(Container, "DataItem.code") %>'																
															name='<%# DataBinder.Eval(Container, "DataItem.name") %>'
															text=''														
                                                            allowselect='0' 
                                                            is_hide="false"
                                                            onclick="tblSubMedia.clickNode(this)"
                                                            onmouseover='this.bgColor="#E3E9F4"' onmouseout='this.bgColor="#ffffff"'>
                                                            <td>
                                                                <span></span><label style="cursor: hand"></label>
                                                                <span>
                                                                    <input type="checkbox" name="chkBld" onclick="selectNode(this)" 
                                                                        value='<%# DataBinder.Eval(Container, "DataItem.code") %>'
                                                                        text='<%# DataBinder.Eval(Container, "DataItem.name") %>'
                                                                        allowselect='<%# DataBinder.Eval(Container, "DataItem.allowselect") %>'>
                                                                </span> 
                                                                <label for="chkBld">
                                                                    <%#DataBinder.Eval(Container, "DataItem.name")%>
                                                                </label>
                                                            </td>
                                                        </tr>
                                                    </ItemTemplate>
                                                    <FooterTemplate>
                                                        </table>
                                                    </FooterTemplate>
                                                </mwc:Repeater>
                                            </div>
                                        </td>
				</tr>
			</table>
			</TD></TR>
			<tr height="40">
				<td class="buttons" style="TEXT-ALIGN:left">
					<asp:Literal id="Literal1" runat="server"></asp:Literal>
				</td>
				<td class="buttons">
					<button style="WIDTH:70px" onclick="selectItem()" id="btnOk" type="button">确 定</button>&nbsp;&nbsp;
					<button style="WIDTH:70px" onclick="parent.window.close();" type="button">取 消</button>
				</td>
			</tr>
		</table>
	</form>
	</body>
</HTML>